<!-- 登陆页面 -->
<template>
  <div>
    <!-- <h1>登陆页面</h1> -->
    <van-nav-bar
  title="账号登陆"
  left-arrow
  @click-left="onClickLeft"
/>
<van-form @submit="onSubmit">
  <van-field
    v-model="formLogin.username"

    placeholder="请输入账号"
    :rules="[{   }]"
  />
  <van-field
    v-model="formLogin.password"
    type="password"

    placeholder="请输入密码"
    :rules="[{ pattern:  /^\d{6}$/ }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit" :loading="isLoading"
            :disabled="isLoading"
            loading-text="程序员拼命加载ing...">提交</van-button>
  </div>
  <div>
    <a href="#/registe">还没有账号,去注册~</a>
  </div>
</van-form>
  </div>
</template>

<script>
import { Toast, Notify } from 'vant'
// import { LoginAPI } from '@/api'
import { mapActions } from 'vuex'

export default {
  data () {
    return {
      isLoading: false,
      formLogin: {
        username: 'hzhmqd',
        password: '123456'
      }

    }
  },
  methods: {
    ...mapActions(['asyncLoginAction']),
    onClickLeft () {
      Toast('返回')
    },
    async onSubmit () {
      this.isLoading = true
      try {
        // const res = await LoginAPI(this.formLogin)
        // console.log(res)
        // const { token } = res.data.body
        // console.log(token)
        await this.asyncLoginAction(this.formLogin)
        Notify({ type: 'success', message: '登录成功' })
        this.isLoading = false
      } catch (err) {
        // console.error(err)
        Notify({ type: 'warning', message: '手机号或密码错误' })
        this.isLoading = false
      }
    }
  }
}

</script>
<style lang='less' scoped>
// .van-nav-bar{
//    background: #21b97a;
// }

// /* /deep/ 就是把data-v-hash值选择器写到类名的前面 */
// /deep/ .van-nav-bar__title{
//   color: white;
// }
</style>
